home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
yerk
/
mps231ss.hqx
/
Mops source
/
Toolbox classes
/
serial
< prev
next >
Wrap
Text File
|
1993-02-01
|
4KB
|
118 lines
\ serial - async serial driver support
\ 2/04/85 cbd Version 1
\ 9/04/86 cdn Eliminated redundant readnw: & writenw
\ 9/06/86 cdn Added bi-directional port usage
\ Automatically send reset: in open:
\ 4/19/89 rfl added break:
\ 6/13/89 rfl requires interval for pause
\ 3/14/90 rfl added buffer:
\ 8/16/90 rfl added baudrate: and XON:
\ NOTE: not yet converted to Mops!!***********************
Decimal
\ define serial i/o port object
:CLASS Port <Super PBDrvr
Int thePort \ 0=modem, 1=printer
Int Direction \ 0=input, 1=output, 2=both
Int Config \ bits, parity, speed
Int inRef \ input IORefNum
Int outRef \ output IORefNum
\ ( port# direction -- )
:M INIT: put: direction put: thePort ;M
\ ( config -- ) set the config word directly
:M SETCONFIG: put: config ;M
\ ( stop data parity -- ) set stop, data bits in the config word
\ stop can be 1 or 2
\ data can be 7 or 8
\ parity: 0=none 1=odd 2=even
:M CONFIG: { stop data parity -- } data 7 =
IF $ 400 ELSE $ C00 THEN -> data stop 1 =
IF $ 4000 ELSE $ C000 THEN -> stop parity 0=
IF $ 2000
ELSE parity 1 =
IF $ 1000
ELSE $ 3000
THEN
THEN -> parity
get: config $ 01FF and data stop parity + + or
put: config ;M
\ set the baud rate for the port - 300,600,1200,2400, etc.
:M BAUD: dup 300 =
IF 80 +
ELSE 300 / 380 swap / 1-
THEN get: config $ FE00 and or put: config
;M
\ do PBControl call
:M CONTROL:
get: direction dup 0= swap 2 = or
IF get: inRef put: IORefNum addr: header fcall PBControl drop THEN
get: direction
IF get: outRef put: IORefNum addr: header fcall PBControl drop THEN
;M
\ set the communication parms from the configuration word
:M RESET: 8 put: csCode get: config put: csp1 0 put: IOComp
control: self ;M
\ ( addr len -- RefNum )
:M OPN: name: super open: super drop get: IORefNum ;M
\ ( -- ) open the read and write drivers for a port
:M OPEN: get: thePort 0=
IF get: direction dup 0= swap 2 = or
IF " .AIn" opn: self put: inRef THEN
get: direction
IF " .AOut" opn: self put: outRef THEN
ELSE get: direction dup 0= swap 2 = or
IF " .BIn" opn: self put: inRef THEN
get: direction
IF " .BOut" opn: self put: outRef THEN
THEN get: IOResult
reset: self
;M
\ ( addr len -- fcode ) receive LEN bytes on the serial port
:M READ: 0 put: IOComp get: inRef put: IORefNum read: super ;M
\ ( addr len -- fcode ) send LEN bytes on the serial port
:M WRITE: 0 put: IOComp get: outRef put: IORefNum write: super ;M
\ ( cfa:proc addr len ) receive LEN bytes asynchronously on the port
:M READNW: get: inRef put: IORefNum readnw: super ;M
\ ( cfa:proc addr len ) send LEN bytes asynchronously on the port
:M WRITENW: get: outRef put: IORefNum writenw: super ;M
\ ( -- char ) get a single character from port
:M GET: pad 1 read: self drop pad c@ ;M
\ ( char -- ) send a single char to port
:M PUT: pad c! pad 1 write: self drop ;M
\ ( bool -- fcode ) turn CTS handshaking on or off via CONTROL call
:M CTS: addr: csp1 10 erase put: csp1 10 put: csCode 0 put: IOComp
control: self get: IOResult
;M
:M XON: ( -- ) 10 put: cscode $ 01001113 addr: csP1 ! control: self ;M
\ sends out a 100 msec break
:M BREAK: 12 put: csCode control: self 6 pause 11 put: csCode control: self ;M
\ ( addr len -- ) increase internal buffer size from default of 64 bytes
:M BUFFER: addr: IOBuffer w! +base addr: csP1 ! 9 put: cscode
control: self
;M
:M BAUDRATE: ( n --) 13 put: cscode put: csP1 control: self ;M
;CLASS